﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace YY.Admin.Converters
{
    public class IconKeyToGeometryConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string iconKey && !string.IsNullOrEmpty(iconKey))
            {
                // 尝试从资源字典中获取图标
                var geometry = System.Windows.Application.Current.TryFindResource(iconKey) as Geometry;

                // 如果找到直接返回
                if (geometry != null) return geometry;

                // 如果找不到，尝试解析为纯路径数据
                try
                {
                    return Geometry.Parse(iconKey);
                }
                catch
                {
                    // 返回默认图标
                    return Geometry.Empty;
                }
            }
            return Geometry.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
